import Vue from 'vue'
import VueRouter from 'vue-router'
//引入首页路由
// eslint-disable-next-line no-unused-vars
import Movie from '../views/home/Movie.vue'

Vue.use(VueRouter)

const routes = [
  //重定向
  {
    path: '/',//根目录
    redirect: '/movie',//路径名称
  },
  {
    path: '/movie',
    name: 'movie',
    component: Movie,
    children: [
      {
        path: '/movie',
        redirect: '/movie/reying'
      },
      {
        path: 'reying',
        name: 'reying',
        component: () => import(/* webpackChunkName: "reying" */ '../views/home/Reying.vue')
      },
      {
        path: 'daiying',
        name: 'daiying',
        component: () => import(/* webpackChunkName: "daiying" */ '../views/home/Daiying.vue')
      },
      {
        path: 'jingdian',
        name: 'jingdian',
        component: () => import(/* webpackChunkName: "jingdian" */ '../views/home/Jingdian.vue')
      },
      {
        path: 'yingyuan',
        name: 'yingyuan',
        component: () => import(/* webpackChunkName: "yingyuan" */ '../views/home/Yingyuan.vue')
      },
    ]
  },
  {
    path: '/video',
    name: 'video',
    component: () => import(/* webpackChunkName: "video" */ '../views/Video.vue')
  },
  {
    path: '/shortvideo',
    name: 'shortvideo',
    component: () => import(/* webpackChunkName: "shortvideo" */ '../views/Shortvideo.vue')
  },
  {
    path: '/show',
    name: 'show',
    component: () => import(/* webpackChunkName: "show" */ '../views/Show.vue')
  },
  {
    path: '/me',
    name: 'me',
    component: () => import(/* webpackChunkName: "me" */ '../views/Me.vue')
  },
  {
    path: '/movieitem/:id',
    name: 'movieitem',
    component: () => import(/* webpackChunkName: "movieitem" */ '../views/MovieItem.vue')
  },
   {
    path: '/citylist',
    name: 'citylist',
    component: () => import(/* webpackChunkName: "citylist" */ '../views/CityList.vue')
  },
   {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue')
  },
  {
    path: '*',
    name: 'page404',
    component: () => import(/* webpackChunkName: "page404" */ '../views/Page404')
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) =>{
  if(to.path == '/me'){
    if(localStorage.getItem('user')){
      next();
    } else{
      next('/login');
    }
  } else{
    next();
  }
})

export default router
